/**
 * 我的小视频详情
 */
import 'package:flutter/material.dart';
import 'package:qgchat/bloc/blocProvider.dart';
import 'package:qgchat/bloc/my/releaseVideoBloc.dart';
import 'package:qgchat/common/global/global.dart';
import 'package:qgchat/http/models/releaseVideoModel.dart';

class Releasevideo extends StatefulWidget {
  Releasevideo({Key key}) : super(key: key);

  @override
  _ReleasevideoState createState() => _ReleasevideoState();
}

class _ReleasevideoState extends State<Releasevideo>
    with SingleTickerProviderStateMixin {
  List inviteList = [0, 1, 3];

  // 跳转发布视频
  void release() {
    goPage(context, '/releasevideo');
  }

  // 构建tabview里面的内容
  Widget getTabview(context, item) {
    return Stack(children: <Widget>[
      GridView.count(
        //水平子Widget之间间距
        crossAxisSpacing: px(22),
        //垂直子Widget之间间距
        mainAxisSpacing: px(22),
        //GridView内边距
        padding: EdgeInsets.only(
          left: px(30),
          right: px(30),
          top: px(20),
        ),
        //一行的Widget数量
        crossAxisCount: 2,
        childAspectRatio: 0.75,
        //子Widget列表
        children: item.map<Widget>((f) {
          return getItemContainer(context, f);
        }).toList(),
      ),
      Positioned(
        bottom: px(77),
        left: px(195),
        child: Container(
          width: px(360),
          height: px(70),
          child: RaisedButton(
            color: col('785fff'),
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(
                px(35),
              ),
            ),
            onPressed: release,
            child: Text(
              '上传视频',
              style: TextStyle(fontSize: px(32), color: Colors.white),
            ),
          ),
        ),
      ),
    ]);
  }

  // 单个小视频
  Widget getItemContainer(context, item) {
    return GestureDetector(
      onTapUp: (val) {
        goPage(
          context,
          '/innervideo',
          param: {'id': item.id, 'image': item.thumbnail},
        );
      },
      child: Container(
        width: px(334),
        height: px(445),
        decoration: ShapeDecoration(
          image: DecorationImage(
            image: NetworkImage("${item.video}?vframe/jpg/offset/0"),
            fit: BoxFit.cover,
          ),
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadiusDirectional.circular(12),
          ),
        ),
        child: Stack(
          children: <Widget>[
            Positioned(
              top: px(15),
              right: px(16),
              child: Container(
                width: px(94),
                height: px(38),
                decoration: BoxDecoration(
                  border: Border.all(width: px(1), color: Colors.white),
                  borderRadius: BorderRadius.all(
                    Radius.circular(
                      px(19),
                    ),
                  ),
                ),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: <Widget>[
                    Image.asset(
                      'assets/images/icon/whitestar.png',
                      width: px(26),
                      height: px(25),
                    ),
                    Container(
                        child: item.paymoney == 0
                            ? Text(
                                '免费',
                                style: TextStyle(
                                  fontSize: px(22),
                                  color: Colors.white,
                                ),
                              )
                            : Text(
                                '付费',
                                style: TextStyle(
                                  fontSize: px(22),
                                  color: Colors.white,
                                ),
                              )),
                  ],
                ),
              ),
            ),
            Positioned(
              bottom: px(15),
              left: px(10),
              child: Container(
                width: px(94),
                height: px(38),
                decoration: BoxDecoration(
                  color: Color.fromRGBO(255, 255, 255, 0.8),
                  border: Border.all(width: px(1), color: Colors.white),
                  borderRadius: BorderRadius.all(
                    Radius.circular(
                      px(19),
                    ),
                  ),
                ),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: <Widget>[
                    Image.asset(
                      'assets/images/icon/heart_red.png',
                      width: px(20),
                      height: px(19),
                    ),
                    Container(
                        child: Text(
                      '${item.watch}',
                      style: TextStyle(
                        fontSize: px(22),
                        color: Colors.red,
                      ),
                    )),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    ReleaseVideoBloc blog = BlocProvider.of<ReleaseVideoBloc>(context);
    return StreamBuilder(
      stream: blog.callStream,
      builder: (
        BuildContext context,
        AsyncSnapshot snapshot,
      ) {
        List<ReleaseVideoModel> list = snapshot.data;
        if (snapshot.hasData) {
          return Scaffold(
            appBar: AppBar(
              title: Text(
                '发布的视频',
                style: TextStyle(fontWeight: FontWeight.bold, fontSize: sp(36)),
              ),
              centerTitle: true,
              actions: [
                FlatButton(
                  onPressed: () {
                    goPage(context, '/coverVideo');
                  },
                  child: Text('封面视频'),
                ),
              ],
            ),
            body: getTabview(context, list),
          );
        } else {
          return Scaffold(
            appBar: AppBar(
              title: Text(
                '发布的视频',
                style: TextStyle(fontWeight: FontWeight.bold, fontSize: sp(36)),
              ),
              centerTitle: true,
            ),
            body: Container(
              width: w100(context),
              height: h100(context),
              child: Stack(
                children: <Widget>[
                  Container(
                    width: w100(context),
                    child: Column(
                      children: <Widget>[
                        Container(
                          margin: EdgeInsets.only(
                            top: px(200),
                          ),
                          child: Image.asset(
                            'assets/images/icon/youjian.png',
                            width: px(272),
                            height: px(303),
                          ),
                        ),
                        Container(
                          margin: EdgeInsets.only(
                            top: px(109),
                          ),
                          child: Text(
                            '我还没有发布视频',
                            style: TextStyle(
                              fontSize: sp(42),
                              color: col('909399'),
                            ),
                          ),
                        )
                      ],
                    ),
                  ),
                  Positioned(
                    bottom: px(80),
                    left: px(200),
                    child: Container(
                      width: px(360),
                      height: px(70),
                      margin: EdgeInsets.only(top: 200),
                      child: RaisedButton(
                        color: col('785fff'),
                        shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(px(35)),
                        ),
                        onPressed: release,
                        child: Text(
                          '上传视频',
                          style: TextStyle(
                            fontSize: px(32),
                            color: Colors.white,
                          ),
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            ),
          );
        }
      },
    );
  }
}
